#include "..\C-Engine\CHeader.hpp"

class Control: public Script
{
    public:
    void Update();
};

void Control::Update()
{
    bool isground = GetObject()->ORigibody->CollisionDecor( GetX() , GetY()-1);
    bool isdo = false;

    if(input_press(K_RIGHT))
    {
        Move(1,0);
        SetIt(1);
        
        isdo = true;
    }
    else if(input_press(K_LEFT))
    {
        Move(-1,0);
        SetIt(1);
        
        isdo = true;
    }

    if(isground == true)
    {
        if(input_trigger(K_UP))
        {
	Move (0,1);
	SetIt(1);
            
        }

        if(isdo == false)
        {
            SetIt(0);
        }
    }
    else
    {
        SetIt(2);
    }

    GetEngine()->MiddleScreen(GetX() + 8 , GetY() + 8);

}

int Jeu()
{

    //*************Sprites*************\\

   const unsigned char I_Perso_1[]={
	0xff, 0xff, 
	0x80, 0x3f, 
	0x84, 0x3f, 
	0x8a, 0x3f, 
	0x8a, 0x3f, 
	0x8c, 0x3f, 
	0x88, 0x3f, 
	0x88, 0x3f, 
	0x80, 0x3f, 
	0x80, 0x3f, 
	0xff, 0xff, 
};
  
Sprite S_Perso_1 (  I_Perso_1  ,  11 , 11 );

Sprite S_Perso[]={ S_Perso_1 ,  };

Animation A_Perso( S_Perso , 1 , 200 );


    //*************Object*************\\

    Object Perso;

    Perso.OTransforms->SetXY( 77 , 45 );
    Perso.ORender->SetRender( A_Perso );
   
    

    Control ScriptPerso;
    Perso.AffectScript(ScriptPerso);

    //*************Map*************\\

const unsigned char tileset[]={
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x3, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x18, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x3, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x18, 0x1f, 
	0x0, 0x1f, 
	0x12, 0x1f, 
	0xfd, 0xff, 
	0x0, 0x1f, 
	0x0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f, 
	0x10, 0x5f, 
	0x20, 0x9f, 
	0x20, 0x9f, 
	0x20, 0x9f, 
	0x20, 0x9f, 
	0x20, 0x9f, 
	0x41, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0xe, 0x1f, 
	0x11, 0x1f, 
	0x20, 0x9f, 
	0x20, 0x9f, 
	0x20, 0x9f, 
	0x20, 0x9f, 
	0x20, 0x9f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
	0x0, 0x1f, 
};
   bool tileprop[]= { true , true , false, true , true , false , true , true , true  ,true , true , true , true , true , true , false , false , false};

const unsigned char * map[]={
	"00000000000000000000",
	"00000000000000000000",
	"0000\?111111111111<00",
	"00006BBBB525BBB5B300",
	"00006BBBB292B5BBB300",
	"00006B5BBBABBBBBB300",
	"0000=4444:@744444>00",
	"0000000006@300000000",
	"0000000006@300000000",
	"0000000006@300000000",
};


    Map Niveau;
    Niveau.SetMap(tileset , map , tileprop , 11 , 11 , 20 ,10);

    //*************Moteur*************\\

    Engine Game;

    Game.AddObject( &Perso);
    Game.AffectMap( &Niveau);

    

    Niveau.AffectEngine( &Game);

    Game.Game();

    return 1;
}

extern "C"
{
int AddIn_main(int isAppli, unsigned short OptionNum)
{
    Jeu();
    return 1;
}


#pragma section _BR_Size
unsigned long BR_Size;
#pragma section


#pragma section _TOP

int InitializeSystem(int isAppli, unsigned short OptionNum)
{
    return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}

#pragma section
}